package cn.lzd.mr.count.writable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 学习：先了解、后深入；先记录、后记忆；先理论、后实践；先模仿、后创新
 * Created by lzd on 2018/5/14.
 */
public class WordCountMr {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(WordCountMr.class);

        job.setMapperClass(WordCountM.class);
        job.setReducerClass(WordCountR.class);

        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(WriteBean.class);

        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(WriteBean.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        boolean res = job.waitForCompletion(true);

        System.exit(res ? 0 : 1);


    }
}
